
$(function(){
    List();

    $('#btn-add').click(function(){
        layOpen('添加','600px','500px','badd.html');
    });
    $('.edit').click(function(){
        let ids = $(this).attr('ids');
        layOpen('编辑','600px','500px','bedit.html?id='+ids)
    });
    $('.info').click(function(){
        let ids = $(this).attr('ids');
        layFirm('删除','admin/BannerDel',{id:ids})
    })
});

function List(){
    let data = AjaxForm('admin/BannerList');
    let html = '';
    if(JSON.stringify(data.data) !== '[]'){
        for (let i=0;i<data.length;i++){
            let show = ``;
            if(data[i].show == 1){
                show = `<p class="info show" ids="${data[i].id}">删除</p>`
            }else{
                show = `<p class="info shownot" ${data[i].id}>删除</p>`
            }
            html += `
            <div class="layui-col-sm4">
                <div class="cmdlist-container">
                    <a href="javascript:;" >
                        <img src="${data[i].content}" ids="${data[i].id}" class="edit">
                        <div class="cmdlist-text">${show}</div>
                    </a>
                </div>
            </div>
           `;
        }
    }else{
        html = `<p style="text-align: center">没有更多数据了</p>`
    }
    $('.layui-row').html(html);
}